package ${package.ServiceImpl};

import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import ${superServiceImplClassPackage};
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * ${table.comment!} 服务实现类
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Slf4j
@Service
<#if kotlin>
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} {

 }
<#else>
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {

    @Override
    @Transactional(rollbackFor = Exception.class)
    public RestResponse add(${entity} bean) {
        // TODO 其他逻辑
        if (save(bean)) {
            return RestResponse.ok();
        } else {
            return RestResponse.error("添加失败");
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public RestResponse delete(IdParamBO req) {
        if (req.getId() != null) {
            if (removeById(req.getId())) {
                return RestResponse.ok("操作成功");
            } else {
                return RestResponse.error("删除失败");
            }
        } else if (req.getIds() != null && !req.getIds().isEmpty()) {
            if (removeByIds(req.getIds())) {
                return RestResponse.ok("操作成功");
            } else {
                return RestResponse.error("批量删除失败");
            }
        } else {
            return RestResponse.error("参数不能为空");
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public RestResponse update(${entity} bean) {
        // TODO 其他逻辑

        if (updateById(bean)) {
            return RestResponse.ok();
        } else {
            return RestResponse.error("修改失败");
        }
    }

    @Override
    public RestResponse detail(Long id) {
        // TODO 其他逻辑

        ${entity} detail = getById(id);
        if (detail == null) {
            return RestResponse.error("数据不存在");
        } else {
            return RestResponse.ok(detail);
        }
    }

    @Override
    public RestResponse listPage(${entity}QueryBO req) {
        // TODO 其他逻辑

        Page<${entity}> pageParams = new Page<>(1, 10);
        LambdaQueryWrapper<${entity}> pageWrapper = new LambdaQueryWrapper();
        // 有其他查询条件，则设置：pageWrapper.eq(${entity}:getxxx(), bean);
        Page<${entity}> pageData = page(pageParams, pageWrapper);
        return RestResponse.ok(pageData);
    }

}
</#if>
